﻿@model IEnumerable<MinistryStandardPlatformWeb.Models.TaskDetailModel>

<style>
    table.complextablelist
    {
        width: 100%;
        display: table;
        border-collapse:collapse;
        border-spacing: 0px;
        border-color: #ccc;
    }

    table.complextablelist td
    {
        text-align: center;
    }

    table.complextablelist th
    {
        text-align: center;
    }

    table.complextablelist tr
    {
        height: 30px;
    }

    table.complextablelist tr td
    {
        border: 1px solid #bbb;
    }

    table.complextablelist tr th
    {
        border: 1px solid #bbb;
    }

    table.complextablelist thead tr
    {
        background:#ccc;
    }


    .complextablehover
    {
        background: rgb(227,235,249);
    }


    table.complextablelist tbody tr.evenclass:not(.complextableselectedrow):not(.complextablehover)
    {
        background:rgb(239,239,239);
    }

    .complextableselectedrow
    {
        background: rgb(97, 128, 219) !important;
    }

</style>
<script type="text/javascript">
    $(document).ready(function () {
        var wholerowlength=16;

        $('@("#taskdetailtable" + @ViewBag.id)' + ' tr:gt(0) td').click(function () {
            $('@("#taskdetailtable" + @ViewBag.id)' + ' tr:gt(0) td').removeClass("complextableselectedrow");

            //点击事件发生的行
            var row = $(this).parent();

            //点击发生在任务单级别
            if (row.children().length == wholerowlength) {
                //点击的是车辆
                
                //如果任务单只有一辆车，则等同于点击任务单
                var rowsNum = Number(row.children().eq(0).attr("rowspan"));
                if (rowsNum <= 1) {
                    row.children().addClass("complextableselectedrow");
                }
                else if ($(this).index() > 8) {
                    row.children().each(function (index, element) {
                        //alert(index);
                        if (index > 8) {
                            $(element).addClass("complextableselectedrow");
                        }
                    });
                }
                else {
                    var rowsNum = row.children().eq(0).attr("rowspan");
                    var currow = row;
                    currow.children().addClass("complextableselectedrow");
                    for (var i = 1; i < rowsNum; i++) {
                        currow = currow.next();
                        currow.children().addClass("complextableselectedrow");
                    }
                }
            }
                //点击发生在车辆级别
            else {
                row.children().addClass("complextableselectedrow");
            }
        });

        $('@("#taskdetailtable" + @ViewBag.id)' + ' tr:gt(0) td').hover(function () {
            $('@("#taskdetailtable" + @ViewBag.id)' + ' tr:gt(0) td').removeClass("complextablehover");

            //hover事件发生的行
            var row = $(this).parent();

            //hover发生在任务单级别
            if (row.children().length == wholerowlength) {
                //hover的是车辆
                //如果任务单只有一辆车，则等同于点击任务单
                var rowsNum = Number(row.children().eq(0).attr("rowspan"));
                //alert(rowsNum);
                if (rowsNum <= 1) {
                    row.children().addClass("complextablehover");
                }
                else if ($(this).index() > 8) {
                    row.children().each(function (index, element) {
                        if (index > 8) {
                            $(element).addClass("complextablehover");
                        }
                    });
                }
                else {
                    var rowsNum = row.children().eq(0).attr("rowspan");
                    var currow = row;
                    currow.children().addClass("complextablehover");
                    for (var i = 1; i < rowsNum; i++) {
                        currow = currow.next();
                        currow.children().addClass("complextablehover");
                    }
                }
            }
                //hover发生在车辆级别
            else {
                row.children().addClass("complextablehover");
            }
        });

        $('@("#taskdetailtable" + @ViewBag.id)' + ' tr:gt(0) td').dblclick(function () {

            //事件发生的行
            var row = $(this).parent();

            //发生在任务单级别
            if (row.children().length == wholerowlength) {

                var rowsNum = row.children().eq(0).attr("rowspan");

                if (rowsNum >1 && $(this).index() > 8) {
                    var id = row.children().eq(9).attr("id");
                    if (id == "-1") //任务单没有车辆
                    {
                        artDialogAlert('该任务单没有车辆');
                        return false;
                    }
                    var title = row.children().eq(9).html() + '车辆位置';
                    //alert(id);
                    if ($("#tt").tabs('exists', title)) {
                        $("#tt").tabs('select', title)
                    }
                    else {
                        var content = '<iframe scrolling="auto" frameborder="0"  src="/DispatchCenter/Map/' + id + '" style="width:100%;height:100%;"></iframe>';
                        $('#tt').tabs('add', {
                            title: title,
                            content: content,
                            cache: false,
                            closable: true
                        });
                        $(".tabs-panels").addClass("box");
                        $(".tabs-panels").addClass("verticalbox");
                        $(".tabs-panels").addClass("fillparentheight");
                        $(".panel").addClass("fillparentheight");
                        $(".panel>div").height($(".panel:visible").height());
                    }
                }
                else {
                    var vid = row.children().eq(9).attr("id");
                    if (vid == "-1") //任务单没有车辆
                    {
                        artDialogAlert('该任务单没有车辆');
                        return false;
                    }
                    var title = row.children().eq(0).html() + '车辆位置';
                    var id = row.attr("id");
                    //alert(id);
                    if ($("#tt").tabs('exists', title)) {
                        $("#tt").tabs('select', title)
                    }
                    else {
                        var content = '<iframe scrolling="auto" frameborder="0"  src="/DispatchCenter/Map/' + id + '" style="width:100%;height:100%;"></iframe>';
                        $('#tt').tabs('add', {
                            title: title,
                            content: content,
                            cache: false,
                            closable: true
                        });
                        $(".tabs-panels").addClass("box");
                        $(".tabs-panels").addClass("verticalbox");
                        $(".tabs-panels").addClass("fillparentheight");
                        $(".panel").addClass("fillparentheight");
                        $(".panel>div").height($(".panel:visible").height());
                    }
                }
            }
                //hover发生在车辆级别
            else {
                var title = row.children().eq(0).html() + '车辆位置';
                var id = row.attr("id");
                //alert(id);
                if ($("#tt").tabs('exists', title)) {
                    $("#tt").tabs('select', title)
                }
                else {
                    var content = '<iframe scrolling="auto" frameborder="0"  src="/DispatchCenter/Map/' + id + '" style="width:100%;height:100%;"></iframe>';
                    $('#tt').tabs('add', {
                        title: title,
                        content: content,
                        cache: false,
                        closable: true
                    });
                    $(".tabs-panels").addClass("box");
                    $(".tabs-panels").addClass("verticalbox");
                    $(".tabs-panels").addClass("fillparentheight");
                    $(".panel").addClass("fillparentheight");
                    $(".panel>div").height($(".panel:visible").height());
                }
            }
        });

        
    });
</script>
@*<input type="hidden" id="id" value="@ViewBag.id" />*@
<table id='@("taskdetailtable" + @ViewBag.id)' class="complextablelist">
    <thead>
        <tr>
            <th>任务单号</th>
            <th>目的地</th>
            <th>运输距离</th>
            <th>标号</th>
            <th>任务量</th>
            <th>累计完成量</th>
            <th>累计完成率</th>
            <th>累计总趟次</th>
            <th>当日总趟次</th>
            <th>车辆</th>
            <th>运输状态</th>
            <th>出站时间</th>
            <th>进工地时间</th>
            <th>本次方量</th>
            <th>本月累计量</th>
            <th>本月累计趟次</th>
        </tr>
    </thead>
    <tbody>
        @{
            int j;
            for (j = 0; j < Model.Count();j++)
            {
                <tr id="@Model.ElementAt(j).TaskId" class="even@(j%2==1)">
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).TaskId</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).Destination</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).Distance</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).Mark</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).TotalVolume</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).CompletedVolume</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">
                        @if(@Model.ElementAt(j).CompleteRate!=-1)
                        {
                            @Model.ElementAt(j).CompleteRate.ToString("P")
                        }
                    </td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).TotalTrip</td>
                    <td rowspan="@Model.ElementAt(j).Vehicles.Count">@Model.ElementAt(j).DayTrip</td>
                    @if(@Model.ElementAt(j).Vehicles.Count>0)
                    {
                        <td id="@Model.ElementAt(j).Vehicles[0].VehicleNum">@Model.ElementAt(j).Vehicles[0].VehicleId</td>
                        <td>@Model.ElementAt(j).Vehicles[0].TranStatus</td>
                        <td>@Model.ElementAt(j).Vehicles[0].LeaveStationTime</td>
                        <td>@Model.ElementAt(j).Vehicles[0].ArriveWorkSiteTime</td>
                        <td>@Model.ElementAt(j).Vehicles[0].ThisTimeVolume</td>
                        <td>@(Model.ElementAt(j).Vehicles[0].MonthVolume==null?0:Model.ElementAt(j).Vehicles[0].MonthVolume)</td>
                        <td>@Model.ElementAt(j).Vehicles[0].MonthTrip</td>
                    }
                    else
                    {
                        <td id="-1"></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    }
                </tr>
                    int i;
                    for (i = 1; i < @Model.ElementAt(j).Vehicles.Count; i++)
                    {
                    <tr id="@Model.ElementAt(j).Vehicles[i].VehicleNum"  class="even@(j % 2 == 1)">
                        <td>@Model.ElementAt(j).Vehicles[i].VehicleId</td>
                        <td>@Model.ElementAt(j).Vehicles[i].TranStatus</td>
                        <td>@Model.ElementAt(j).Vehicles[i].LeaveStationTime</td>
                        <td>@Model.ElementAt(j).Vehicles[i].ArriveWorkSiteTime</td>
                        <td>@Model.ElementAt(j).Vehicles[i].ThisTimeVolume</td>
                        <td>@(Model.ElementAt(j).Vehicles[i].MonthVolume==null?0:Model.ElementAt(j).Vehicles[i].MonthVolume)</td>
                        <td>@Model.ElementAt(j).Vehicles[i].MonthTrip</td>
                    </tr>
                }
            }
        }
    </tbody>
</table>
@*<script type="text/javascript">
    registertableevent();
</script>*@
